
// do "/projects/hsieh_project/code_0_general/f_lpolyci.do"

capture program drop lpolyci_data
program lpolyci_data
	args df_in df_out v_y v_x v_conf v_n c_weight v_bwidth
	
	if "`df_in'" == "" local df_in = "default"
	di "`df_in' `df_out' `v_y' `v_x' `v_conf'"
	capture frame change `df_in'
	capture frame drop `df_out'
	frame copy `df_in' `df_out', replace
	frame change `df_out'
	lpoly `v_y' `v_x' `c_weight', nograph ///
		bwidth(`v_bwidth') n(`v_n') ///
		gen(`v_y'_x `v_y'_s) se(`v_y'_se) ci level(`v_conf')
	keep `v_y'_x `v_y'_s `v_y'_se
	
	local cr_val = invnormal(0.5+`v_conf'/200)
	gen `v_y'_ciu = `v_y'_s + `cr_val' * `v_y'_se
	gen `v_y'_cil = `v_y'_s - `cr_val' * `v_y'_se
	
	gen row_id = _n
	
	frame change `df_in'
	
end
